package com.juc.scheduledExecutorService.scheduledExecutorService11;

import java.util.Iterator;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Run1 {

	//方法cancel(boolean)与setRemoveOnCancelPolicy
	/**
	 * cancel(boolean)作用：设定是否取消任务
	 * setRemoveOnCancelPolicy(boolean)作用：设定是否将取消后的任务
	 * 从队列中清除
	 * 
	 */
	public static void main(String[] args) {
		ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(10);
		Runnable runnable1 = new MyRunnable("A");
		ScheduledFuture<?> feFuture = executor.schedule(runnable1, 1, TimeUnit.SECONDS);
		System.out.println(feFuture.cancel(true));
		System.out.println("");
		BlockingQueue<Runnable> queue = executor.getQueue();
		Iterator<Runnable> iterator = queue.iterator();
		while(iterator.hasNext()) {
			Runnable runnable = iterator.next();
			System.out.println("队列中 的   "+ runnable);
		}
		System.out.println("main end !");
	}
}
